<!DOCTYPE html>
<html>
    <head>
            <title>简版加密工具</title>
                <style>
                            body{font-family:Arial;max-width:600px;margin:0 auto;padding:20px}
                                    .box{margin:15px 0;padding:15px;border:1px solid #ddd;border-radius:5px}
                                            textarea,input{width:100%;padding:8px;margin:8px 0;box-sizing:border-box}
                                                    button{padding:8px 15px;background:#4CAF50;color:#fff;border:none;border-radius:4px;cursor:pointer}
                                                            .result{margin-top:10px;padding:10px;background:#f5f5f5;border-radius:4px;word-break:break-all}
                                                                </style>
                                                                </head>
                                                                <body>
                                                                        <h1>简版加密工具（如果复制失败请长按代码复制）</h1>
                                                                            
                                                                                <div class="box">
                                                                                            <h3>加密文字</h3>
                                                                                                    <textarea id="encryptText" placeholder="输入要加密的文字"></textarea>
                                                                                                            <button onclick="encrypt()">生成代码</button>
                                                                                                                    <div id="encryptResult" style="display:none">
                                                                                                                                    <div class="result" id="encryptCode"></div>
                                                                                                                                                <button onclick="copy('encryptCode')">复制</button>
                                                                                                                                                        </div>
                                                                                                                                                            </div>
                                                                                                                                                                
                                                                                                                                                                    <div class="box">
                                                                                                                                                                                <h3>解密代码</h3>
                                                                                                                                                                                        <textarea id="decryptCode" placeholder="输入加密代码"></textarea>
                                                                                                                                                                                                <button onclick="decrypt()">解密</button>
                                                                                                                                                                                                        <div id="decryptResult" style="display:none">
                                                                                                                                                                                                                        <div class="result" id="decryptedText"></div>
                                                                                                                                                                                                                                </div>
                                                                                                                                                                                                                                    </div>

                                                                                                                                                                                                                                        <script>
                                                                                                                                                                                                                                                    function encrypt(){
                                                                                                                                                                                                                                                                let text = document.getElementById("encryptText").value.trim();
                                                                                                                                                                                                                                                                            if(!text) return alert("请输入文字");
                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                    // 生成加密代码: 前缀+随机数+加密数据
                                                                                                                                                                                                                                                                                                                let encrypted = "";
                                                                                                                                                                                                                                                                                                                            for(let i=0; i<text.length; i++){
                                                                                                                                                                                                                                                                                                                                            encrypted += String.fromCharCode(text.charCodeAt(i)+3);
                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                    let code = "sytimehtml_" + Math.random().toString(36).substr(2,8) + "_" + btoa(encrypted);
                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                                            document.getElementById("encryptCode").textContent = code;
                                                                                                                                                                                                                                                                                                                                                                                                        document.getElementById("encryptResult").style.display = "block";
                                                                                                                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                                                                                                                                        function decrypt(){
                                                                                                                                                                                                                                                                                                                                                                                                                                    let code = document.getElementById("decryptCode").value.trim();
                                                                                                                                                                                                                                                                                                                                                                                                                                                if(!code.startsWith("sytimehtml_")) return alert("无效代码");
                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        try {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        let encrypted = atob(code.split("_")[2]);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        let text = "";
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        for(let i=0; i<encrypted.length; i++){
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            text += String.fromCharCode(encrypted.charCodeAt(i)-3);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            document.getElementById("decryptedText").textContent = text;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            document.getElementById("decryptResult").style.display = "block";
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        } catch(e) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        alert("解密失败");
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    function copy(id){
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                navigator.clipboard.writeText(document.getElementById(id).textContent)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                .then(() => alert("已复制"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                .catch(() => alert("复制失败"));
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </body>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </html>j